package com.baizhi.method;

/**
 *   有时候我们是需要强制唤醒休眠线程的
 *   像sleep这样的方法会导致线程进入阻塞状态，该方法要求必须处理中断异常InterruptedException
 *
 *   当一个线程调用slepp处于阻塞状态的过程中该线程的interrupt方法被调用了，那么就会立马中断该线程的阻塞，此时sleep方法抛出
 *   InterruptedException异常
 */
public class SleepDemo02 {
    public static void main(String[] args) {
        Thread lin = new Thread(){
            @Override
            public void run() {
                System.out.println("林：刚刚做完美容，睡一会吧~~~~~");

                try {
                    Thread.sleep(1000000000);
                    System.out.println("林：睡醒了");
                } catch (InterruptedException e) {
                    System.out.println("林：干嘛呢！干嘛呢？干嘛呢? 都破了相了~~~~~~");

                }

            }
        };


        Thread huang = new Thread(){
            @Override
            public void run() {
                System.out.println("黄：大锤八十，小锤四十，开始凿墙");
                for (int i = 0; i < 5; i++) {
                    System.out.println("黄：80!!!");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("咣当");
                System.out.println("黄：大哥，搞定！！！！！");
                // 唤醒lin
                lin.interrupt(); //中断了lin的sleep方法
            }
        };


        lin.start();
        huang.start();
    }
}



